#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int maxn = 200 + 50;

int F[maxn];
int n, m;

void Init() {
    for (int i = 1; i <= n; i++)F[i] = i;
}

int Find(int x) {
    return x == F[x] ? x : (F[x] = Find(F[x]));
}

bool Merge(int x, int y) {
    int fx = Find(x), fy = Find(y);
    if (fx == fy)return false;
    F[fy] = fx;
    return true;
}

int Count() {
    int tot = 0;
    for (int i = 1; i <= n; i++) {
        if (F[i] == i) {
            ++tot;
        }
    }
    return tot;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ifstream fin("B.in");
    if (fin.good()) cin.rdbuf(fin.rdbuf());
    while (cin >> n >> m) {
        if (n == 0 && m == 0)break;
        Init();
        while (m--) {
            int x, y;
            x++;
            y++;
            cin >> x >> y;
            Merge(x, y);
        }
        cout << Count() - 1 << endl;
    }

    return 0;
}